<?php

class spInvoice extends spDiv
{
	public function __construct( $fullname, $address, $email, $telephone, $orderTitle, $orderDescription, $orderPrice, $orderDate, $orderNumber )
	{
		parent::__construct(array(
			"style" => array(
				"width" => "640px",
				"border" => "solid 10px #A4A4A4"
		)));
		
		$inside = new spDiv(array(
			"style" => array(
				"border" => "solid 6px #0B610B",
				"padding" => "2px"
			)
		));
		parent::addChild( $inside );
		
		$inside->addChild( $this->createHeading(
			$fullname,
			$orderDate,
			$orderNumber
		));
		$inside->addChild( $this->createHr() );
		
		$inside->addChild( $this->createBillingAddress(
			$fullname,
			$address,
			$email,
			$telephone
		));
		$inside->addChild( $this->createHr() );
		
		$inside->addChild( $this->createYourOrder(
			$orderTitle,
			$orderDescription,
			$orderPrice
		));
		$inside->addChild( $this->createHr() );

		$inside->addChild( $this->createPaymentConditions() );
		$inside->addChild( $this->createHr() );

		$inside->addChild( $this->createContactInformation() );
	}
	
	private function createHr()
	{
		return new spHorizontalLine(array(
			"style" => array(
				"border" => "solid 1px black"
			)
		));
	}
	
	private function createTable()
	{
		$table = new spTable(array(
			"x" => "2",
			"y" => "1",
			"style_td" => array(
				"vertical-align" => "top"
			),
			"style" => array(
				"width" => "100%"
			)
		));

		$left = $table->getCell(0,0);
		$right = $table->getCell(1,0);
		$right->addStyle( "float", "right" );
		
		return array( $table, $left, $right );
	}
	
	private function createFont( $text )
	{
		return new spFont(array(
			"face" 		=> "Verdana, Geneva, sans-serif",
			"font-size"	=> "20px",
			"content" 	=> $text
		));
	}

	private function createHeading( $fullname, $date, $ordernumber )
	{
		list( $table, $left, $right ) = $this->createTable();		
		
		$left->addChild( $this->createFont( $fullname ) );
		$left->addChild( new spTextLines(array(
			"<br/>",
			ttfL("invoicethanks")
		)));
		
		$right->addChild(new spParagraph(array(
			"content" => ttfL("invoicedate").": ".$date."<br/>".ttfL("invoiceordernumber").": ".$ordernumber
		)));
		
		return $table;
	}

	private function createBillingAddress( $fullname, $address, $email, $telephone )
	{
		list( $table, $left, $right ) = $this->createTable();
		
		$left->addChild( $this->createFont( ttfL("invoicepaymentaddress") ) );
		
		$left->addChild( new spTextLines(array(
			"<br/>",
			$fullname,
			$address,
			$email,
			$telephone
		)));
		
		return $table;
	}	
	
	private function createYourOrder( $orderTitle, $description, $price  )
	{
		$c = new spDiv;
		
		list( $table, $left, $right ) = $this->createTable();
		$left->addChild( $this->createFont( ttfL("invoiceyourorder") ) );
		$c->addChild( $table );
		
		$c->addChild( new spBreak );

		list( $table, $left, $right ) = $this->createTable();
		$left->addChild( new spTextLines(array(
			"<b>".ttfL("invoicemerchandise")."</b>",
			$orderTitle,
			$description
		)));
		$right->addChild( new spTextLines(array(
			"<b>".ttfL("invoiceprice")."</b>",
			$price." DKK"
		)));
		$c->addChild( $table );
		
		return $c;
	}
	
	private function createPaymentConditions()
	{
		list( $table, $left, $right ) = $this->createTable();
		
		$left->addChild( $this->createFont( ttfL("paymentconditionstitle") ) );
		
		$left->addChild( new spTextLines(array(
			"<br/>",
			ttfL( "paymentconditions" )
		)));		
		
		return $table;
	}

	private function createContactInformation()
	{
		$c = new spDiv;
	
		$c->addChild( new spFont(array(
			"face" 		=> "Verdana, Geneva, sans-serif",
			"font-size"	=> "20px",
			"content"	=> ttfL("invoicecontact")
		)));
		
		$c->addChild( new spBreak );
		$c->addChild( new spBreak );		
		
		$c->addChild( new spDiv(array(
			"content" => "Tumbling Team Fyn<br/>Gyvelvej 8<br/>5250 Odense SV<br/><br/>".ttfL("invoicetelephone").": 23311833<br/>".ttfL("invoiceemail").": <a href='mailto:tumblingteamfyn@gmail.com'>tumblingteamfyn@gmail.com</a>"
		)));

		return $c;
	}	
}

?>